/**
 */
package wcomm_v1.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import wcomm_v1.Activity;
import wcomm_v1.Region;
import wcomm_v1.State;
import wcomm_v1.Wcomm_v1Package;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>State</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link wcomm_v1.impl.StateImpl#getOnEntry <em>On Entry</em>}</li>
 *   <li>{@link wcomm_v1.impl.StateImpl#getDoActivity <em>Do Activity</em>}</li>
 *   <li>{@link wcomm_v1.impl.StateImpl#getOnExit <em>On Exit</em>}</li>
 *   <li>{@link wcomm_v1.impl.StateImpl#getRegions <em>Regions</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class StateImpl extends VertexImpl implements State
{
  /**
   * The cached value of the '{@link #getOnEntry() <em>On Entry</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOnEntry()
   * @generated
   * @ordered
   */
  protected Activity onEntry;

  /**
   * The cached value of the '{@link #getDoActivity() <em>Do Activity</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDoActivity()
   * @generated
   * @ordered
   */
  protected Activity doActivity;

  /**
   * The cached value of the '{@link #getOnExit() <em>On Exit</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOnExit()
   * @generated
   * @ordered
   */
  protected Activity onExit;

  /**
   * The cached value of the '{@link #getRegions() <em>Regions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRegions()
   * @generated
   * @ordered
   */
  protected EList<Region> regions;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected StateImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return Wcomm_v1Package.Literals.STATE;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Activity getOnEntry()
  {
    return onEntry;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetOnEntry(Activity newOnEntry, NotificationChain msgs)
  {
    Activity oldOnEntry = onEntry;
    onEntry = newOnEntry;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__ON_ENTRY, oldOnEntry, newOnEntry);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setOnEntry(Activity newOnEntry)
  {
    if (newOnEntry != onEntry)
    {
      NotificationChain msgs = null;
      if (onEntry != null)
        msgs = ((InternalEObject)onEntry).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__ON_ENTRY, null, msgs);
      if (newOnEntry != null)
        msgs = ((InternalEObject)newOnEntry).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__ON_ENTRY, null, msgs);
      msgs = basicSetOnEntry(newOnEntry, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__ON_ENTRY, newOnEntry, newOnEntry));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Activity getDoActivity()
  {
    return doActivity;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDoActivity(Activity newDoActivity, NotificationChain msgs)
  {
    Activity oldDoActivity = doActivity;
    doActivity = newDoActivity;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__DO_ACTIVITY, oldDoActivity, newDoActivity);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDoActivity(Activity newDoActivity)
  {
    if (newDoActivity != doActivity)
    {
      NotificationChain msgs = null;
      if (doActivity != null)
        msgs = ((InternalEObject)doActivity).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__DO_ACTIVITY, null, msgs);
      if (newDoActivity != null)
        msgs = ((InternalEObject)newDoActivity).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__DO_ACTIVITY, null, msgs);
      msgs = basicSetDoActivity(newDoActivity, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__DO_ACTIVITY, newDoActivity, newDoActivity));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Activity getOnExit()
  {
    return onExit;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetOnExit(Activity newOnExit, NotificationChain msgs)
  {
    Activity oldOnExit = onExit;
    onExit = newOnExit;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__ON_EXIT, oldOnExit, newOnExit);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setOnExit(Activity newOnExit)
  {
    if (newOnExit != onExit)
    {
      NotificationChain msgs = null;
      if (onExit != null)
        msgs = ((InternalEObject)onExit).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__ON_EXIT, null, msgs);
      if (newOnExit != null)
        msgs = ((InternalEObject)newOnExit).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Wcomm_v1Package.STATE__ON_EXIT, null, msgs);
      msgs = basicSetOnExit(newOnExit, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, Wcomm_v1Package.STATE__ON_EXIT, newOnExit, newOnExit));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Region> getRegions()
  {
    if (regions == null)
    {
      regions = new EObjectContainmentEList<Region>(Region.class, this, Wcomm_v1Package.STATE__REGIONS);
    }
    return regions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.STATE__ON_ENTRY:
        return basicSetOnEntry(null, msgs);
      case Wcomm_v1Package.STATE__DO_ACTIVITY:
        return basicSetDoActivity(null, msgs);
      case Wcomm_v1Package.STATE__ON_EXIT:
        return basicSetOnExit(null, msgs);
      case Wcomm_v1Package.STATE__REGIONS:
        return ((InternalEList<?>)getRegions()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.STATE__ON_ENTRY:
        return getOnEntry();
      case Wcomm_v1Package.STATE__DO_ACTIVITY:
        return getDoActivity();
      case Wcomm_v1Package.STATE__ON_EXIT:
        return getOnExit();
      case Wcomm_v1Package.STATE__REGIONS:
        return getRegions();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.STATE__ON_ENTRY:
        setOnEntry((Activity)newValue);
        return;
      case Wcomm_v1Package.STATE__DO_ACTIVITY:
        setDoActivity((Activity)newValue);
        return;
      case Wcomm_v1Package.STATE__ON_EXIT:
        setOnExit((Activity)newValue);
        return;
      case Wcomm_v1Package.STATE__REGIONS:
        getRegions().clear();
        getRegions().addAll((Collection<? extends Region>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.STATE__ON_ENTRY:
        setOnEntry((Activity)null);
        return;
      case Wcomm_v1Package.STATE__DO_ACTIVITY:
        setDoActivity((Activity)null);
        return;
      case Wcomm_v1Package.STATE__ON_EXIT:
        setOnExit((Activity)null);
        return;
      case Wcomm_v1Package.STATE__REGIONS:
        getRegions().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case Wcomm_v1Package.STATE__ON_ENTRY:
        return onEntry != null;
      case Wcomm_v1Package.STATE__DO_ACTIVITY:
        return doActivity != null;
      case Wcomm_v1Package.STATE__ON_EXIT:
        return onExit != null;
      case Wcomm_v1Package.STATE__REGIONS:
        return regions != null && !regions.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //StateImpl
